Repository navigation
Only make config more permissive in tests that need it - #1648
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1544
Edit: When making this PR, I didn't notice #1647, which was recently opened (but opened before this PR; #1647 came first). That PR includes an alternative to the approach taken here. It uses a GitPython feature to set
protocol.file.allowingitcommand-like arguments, while this patchesGIT_CONFIG_*environment variables. Both approaches are specific and, I believe, robust. The approach in this PR avoids using more GitPython features that are not conceptually under test in the submodule tests. But the approach in #1647 is significantly more compact, which might be considered the more important benefit. I will not mind if this is closed in preference for #1647! At this time, both #1647 and this PR also contain changes beyond those that directly address #1544, and another option, if the approach in #1647 is chosen, would be for me to narrow this PR to make only CI changes, after #1647 is accepted.(The original description of the changes in this PR, and the rationale for them, follows.)
protocol.file.allow
This eliminates the need for users running the test suite to set
protocol.file.allowtoalwaysin the global git configuration. Setting it globally toalwayshas security implications, as alluded to in #1544, and as noted in the description in git release notes of how CVE-2022-39253 was fixed, and in git/git@a1d4f67 where its default value was changed fromalwaystouser.On CI, this was not directly a problem, because the CI runner is isolated and not being used to clone unrelated less-trusted repositories. But users are likely to be looking at the CI workflows to figure out how to overcome the
fatal: transport 'file' not allowederror locally. Furthermore, by having the test suite make the change automatically and temporarily by modifying process environment variables, the needed setup is simplified for everyone.The approach taken here is inspired by #1544 (comment) and makes use of
GIT_CONFIG_*environment variables. But it is more specific than suggested there, instead temporarily patching the environment only during the runs of the two specific tests that require it,test_list_only_valid_submodulesandtest_git_submodules_and_add_sm_with_new_commit. This is done without much code duplication, so it can be applied easily to any future test cases that require it. (I think this probably won't ever be needed outsidetest_submodule.py, because Git's default value ofprotocol.file.allowisuser, notnever.)I patched
GIT_CONFIG_*variables in such a way that existing assignments toGIT_CONFIG_*variables, if present, are still used, rather than being replaced or causing an error. I considered patchingGIT_ALLOW_PROTOCOLinstead, but I decided against it because it may be useful for people running the tests to be able to change what other protocols are allowed/disallowed. PatchingGIT_ALLOW_PROTOCOLin a way that respected that would be more complicated than patchingGIT_CONFIG_*variables.safe.directory
protocol.file.allowis one of two security-related configuration options that were set on CI. The other issafe.directory. This is not needed in thepythonpackage.ymlworkflow, because the cloned repository's files are always owned by the same user that is runningpytestand thusgit, so I removed it from there. Thecygwin-test.ymlworkflow does currently need it, and I shell-quoted$(pwd)there, which is slightly more robust and better expresses the intent that no splitting or globbing be performed, but otherwise retained it.I was unsure if I should include changes related to
safe.directoryin this PR, or open a separate PR. Theprotocol.file.allowandsafe.directorycustomizations were presented as closely related in the workflows. More importantly, to decide where to put the fixture/helper used for patchingprotocol.file.allowintest_submodule.py, I checked that it would not be needed elsewhere, by verifying that no test cases inherently requiresafe.directoryto be set (but that it just works around a Cygwin-specific issue). For the same reason, it seems to me that the changes may be easier to review together than separately, as well. However, I would be pleased to make any requested changes to this PR, including splitting outsafe.directory-related changes to a separate PR if desired.